<template>
  <div class="warp-box">
    <el-row class="search-box" style="margin-top: 30px;">
      <el-col :span="24">
        <div class="search-div">
          <el-input style="width:266px;" v-model="phone" placeholder="请输入手机号码"></el-input>
        </div>
        <div class="search-div">
          <span class="search-btn backorgin" @click="search">搜索</span>
        </div>
      </el-col>
    </el-row>
    <div class="main-box channel1234">
      <div class="inforlist" v-cloak>
        <el-table :data="dataList" style="margin-top:20px;font-size:16px;" v-loading="loading">
          
          <el-table-column prop="phone" label="手机号码"></el-table-column>
          <el-table-column prop="promoteUrlName" label="渠道名称"></el-table-column>
          <el-table-column prop="limit" label="H5注册时间">
            <template slot-scope="scope">
              <span v-if="scope.row.registerTime">{{formatDate(new Date(scope.row.registerTime))}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="uv" label="APP登录时间">
              <template slot-scope="scope">
              <span v-if="scope.row.loginTime">{{formatDate(new Date(scope.row.loginTime))}}</span>
            </template>
          </el-table-column>
        </el-table>
        <div class="pages-box">
          <div style="text-align:center;margin-top:20px;">
            <el-pagination
              background
              @current-change="handleCurrentChange"
              :current-page="start"
              :page-size="limit"
              layout="total, prev, pager, next, jumper"
              :total="total"
            ></el-pagination>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loading: false,
      start: 0,
      limit: 5,
      total: 0,
      phone: "",
      dataList: []
    };
  },
  methods: {
    handleCurrentChange(val) {
      //页码切换
      var that = this;
      that.start = val;
      that.render();
    },
    render() {
      this.loading = true;
      this.$axios
        .get("/tx/phone/list", {
          start: this.start,
          limit: this.limit,
          phone: this.phone
        })
        .then(res => {
          if (res.code === 10200) {
            this.dataList = res.data.list;
            this.total = res.data.count;
          }
          setTimeout(() => {
            this.loading = false;
          }, 200);
        });
    },
    formatDate(now) {
      var year = now.getFullYear(),
        month = now.getMonth() + 1,
        date = now.getDate(),
        hour = now.getHours(),
        minute = now.getMinutes(),
        second = now.getSeconds();
      return year + "-" + month + "-" + date +" " + hour + ":"+minute+":"+second;
    },
    search() {
      //查询
      this.start = 0;
      this.render();
    }
  },
  mounted() {
    this.render();
  }
};
</script>
